oTarget = oUF:NewModule("oUF_Target", oUF.unit.target)

function oTarget:Enable()
	self:disableBlizzard()
	oUF.unit.target = oUF.class.unit:new("target")
	oUF.unit.target:loadPosition()
	self:createCP()
	self:RegisterEvent("PLAYER_COMBO_POINTS", "updateCP")
	self:RegisterEvent("PLAYER_TARGET_CHANGED", "updateTarget")
end

function oTarget:updateTarget()
	if(UnitExists("target")) then
		oUF.unit.target:updateAll()
		self:updateReaction()
		self:updateCP()
	end
end

function oTarget:createCP()
	local c = select(2, UnitClass("player"))

	if(c == "ROGUE" or c == "DRUID") then
		oUF.unit.target.CPoints = oUF.unit.target:CreateFontString(nil, "OVERLAY")
		oUF.unit.target.CPoints:SetFont("Fonts\\FRIZQT__.TTF", 24, "THICKOUTLINE")
		oUF.unit.target.CPoints:SetTextColor(1, 1, 1)
		oUF.unit.target.CPoints:SetPoint("LEFT", oUF.unit.target, "RIGHT", 5, -1)
		oUF.unit.target.CPoints:SetJustifyH("LEFT")
	end
end

function oTarget:updateReaction()
	local r, g, b = oUF:GetReactionColors("target")
	oUF.unit.target:SetBackdropBorderColor(r, g, b)
end

function oTarget:updateCP()
	if not self.CPoints then return end
	
	if(GetComboPoints() > 0) then
		self.CPoints:SetText(GetComboPoints())
	else
		self.CPoints:SetText(nil)
	end
end

function oTarget:disableBlizzard()
	TargetFrame:UnregisterAllEvents()
end
